﻿<?
	include '../inc/conn.php';
	session_start();
	extract($_POST);
	extract($_GET);
	unset($_POST,$_GET);
	
	if(!isset($_SESSION['logname'])){
		die("<div>User Session is missing</div>");
	}
	
	if (isset($act) && isset($id))
	{
		if (empty($iTitle) || empty($iWritor) ||empty($vContent)){
			echo "<script>alert('Some content must be filled in data!!');window.history.go(-1);</script>";
			die("Some content must be filled in data!");
		}
		if ($act == 'mod')
		{	
			date_default_timezone_set('Asia/Shanghai');
			$dt = date("Y-m-d H:i:s");
			$db = new mysql();
			$table = "te_wiki_table";
			$condition = "id=".$id;
			$mod_content="wiki_title='".htmlentities($iTitle,ENT_QUOTES)."', wiki_writor='".htmlentities($iWritor,ENT_QUOTES)."', 
			wiki_body='".htmlentities($vContent,ENT_QUOTES)."'";	
			
			$db->update($table, $mod_content, $condition);
			$db->close();
			echo "<script>alert('数据修改完成!');window.opener.location.reload();window.close();</script>";
		}
	}
	
	if (!isset($id))
	{
		echo "<script>alert('ID is empty!');</script>";
		die("ID is empty!");
	}
	$db = new mysql();
	$sql = "select * from te_wiki_table where id=".$id;
	$db->query($sql);
	$num = $db->db_num_rows();
	if ($num == 0)
		die("No data was found!");
	$row = $db->fetch_assoc();
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">-->
<link rel="stylesheet" href="/css/bootstrap.min.css">
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/js/jquery-migrate.min.js"></script>
<script type="text/javascript" src="/xhEditor/xheditor.min.js"></script>
<script type="text/javascript" src="/xhEditor/xheditor_lang/zh-cn.js"></script>
<script type="text/javascript" src="/js/bootstrap.min.js"></script>
<style>
<!--
.xheDialog label {
	display: inline;
}
.form-horizontal .control-label {
	width: 80px;
}
.form-horizontal .controls {
	margin-left: 20px;
}
-->
</style>
<title>修改 "<? echo htmlspecialchars_decode($row['wiki_title']); ?>" 详细信息</title>
</head>
<body class="background">
<?
	include "admin_top.php";
?>
<div class="container white-background pagecontent">
<div class="panel panel-primary">
    <div class="panel-heading">
        <h3 class="panel-title">修改 "<? echo htmlspecialchars_decode($row['wiki_title']); ?>" 详细信息</h3>
    </div>
    <div class="panel-body">
	<form action="mod_wiki.php?id=<?echo $row['ID']?>&act=mod" method="post" enctype="application/x-www-form-urlencoded">
	<div class="input-group">
		<span class="input-group-addon">标题:</span><input name="iTitle" type="text" value="<? echo htmlspecialchars_decode($row['wiki_title']); ?>" class="form-control">
	</div>
	<div class="input-group">
		<span class="input-group-addon">作者:</span><input name="iWritor" type="text" value="<? echo htmlspecialchars_decode($row['wiki_writor']); ?>" class="form-control">
	</div>
<div>
维基内容:<br />
<textarea name="vContent" rows="12" cols="80" class="xheditor {tools:'full',skin:'default', upImgUrl:'upload.php?immediate=1'}" style="width:100%;height:280px; no-repeat right bottom fixed">
<? echo htmlspecialchars_decode($row['wiki_body']); ?>
</textarea>
<div><input class="btn btn-success btn-primary" name="submit" value="修改" type="submit"><input class="btn btn-danger" name="reset" value="重填" type="reset"></div>
</div>
</form>
</div>
</div>
</div>
<?
include '../bottom.php';
?>
</body>
</html>
<?
	$db->close();
?>
